//
//  ViewController.m
//  UI24-(加密+解密)
//
//  Created by 韩旭 on 16/8/16.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textFiledEncrypt;
@property (weak, nonatomic) IBOutlet UITextField *textFieldDecode;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
}
- (IBAction)加密:(id)sender {
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
    NSString *parameters = [NSString stringWithFormat:@"text=%@", _textFiledEncrypt];
   [manger.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        return parameters;
    }];
    NSString *url = @"http://tool.zzblo.com/api/md5/encrypt";
    [manger POST:url parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        _textFieldDecode.text = responseObject[@"secret16"];
        NSLog(@"%@", responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}
- (IBAction)解密:(id)sender {
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
    NSString *stringUrl = @"http://tool.zzblo.com/api/md5/decrypt";
    NSString *parameters = [NSString stringWithFormat:@"secret=%@", _textFieldDecode.text];
   [manger.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
       return parameters;
    }];
   [manger POST:stringUrl parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       _textFiledEncrypt.text = responseObject[@"text"];
       NSLog(@"%@", responseObject);
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
   }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
